package top.lishuoboy.spring.jdbc_template.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import top.lishuoboy.spring.jdbc_template.dao.UserDao;

@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
//    @Transactional(propagation = Propagation.REQUIRES_NEW)   // 31.测试事务传播行为
    public void addMoney(int money, int inId) {
        String sql = "update account set money = money + ? where id = ? ";
        jdbcTemplate.update(sql, money, inId);
    }

    @Override
    public void reduceMoney(int money, int outId) {
        String sql = "";
        sql = "update account set money = money - ? where id = ?";
//        sql = "update account set money = money - ? where id1 = ?";  // 造异常
        jdbcTemplate.update(sql, money, outId);
    }
}